package com.neusoft.neuiotms.support.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.bizcore.web.bean.LogBean;
import com.neusoft.bizcore.web.dto.result.PageResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultListDTO;
import com.neusoft.bizcore.web.support.Searchable;
import com.neusoft.neuiotms.support.service.LogService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api("日志管理")
@RestController
@RequestMapping(value = "/api/w/logs")
public class LogController {

    @Autowired
    private LogService logService;

    @ApiOperation("查询日志")
    @GetMapping
    public ResultListDTO<LogBean> index(final Searchable searchable) {
        final List<LogBean> beans = this.logService.search(searchable);
        return ResultListDTO.success(beans);
    }

    @ApiOperation("分页查询日志")
    @GetMapping("/p")
    public PageResultDTO<LogBean> search(final Searchable searchable, final Pageable pageable) {
        final Page<LogBean> logs = this.logService.search(pageable, searchable);
        return PageResultDTO.success(logs);
    }

    @ApiOperation("创建日志记录")
    @PostMapping
    public ResultDTO<LogBean> create(@RequestBody final LogBean bean) {
        this.logService.save(bean);
        return ResultDTO.success(bean);
    }

}
